package org.example.controller;


import org.example.base.ResultInfo;
import org.example.exceptions.ParamsException;
import org.example.model.UserBo;
import org.example.service.UserService;
import org.example.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName UserController
 * @Author lidahu
 * @Description //TODO
 * @Date 2023/2/5 23:17
 **/
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("login")
    public ResultInfo userLogin(User user) {
        ResultInfo resultInfo = new ResultInfo();
        try {
            UserBo userBo = userService.selectUser(user);
            resultInfo.setResult(userBo);
        } catch (ParamsException p) {
            resultInfo.setCode(p.getCode());
            resultInfo.setMsg(p.getMsg());
            p.printStackTrace();
        } catch (Exception e) {
            resultInfo.setCode(500);
            resultInfo.setMsg("登录失败！");
        }
        return resultInfo;
    }


}
